<?php
	session_start();
	require('setup/file_txt.inc.php');
	getConfig('setup/config.ini');
	$urls = getUrls('setup/url.ini');

	if(isset($_GET['tokey']) && isset($_GET['keyword']) && isset($_GET['url'])){
		if($_GET['tokey']!=$tokey){
			exit("error");
		}

		$url = $_GET['url'];
		if(strpos($url,"{IP}")){
			$url = str_replace("{IP}",$_SERVER['REMOTE_ADDR'],$url);
		}

		$urls[$_GET['keyword']] = $url;
		// 将修改后的内容写回 INI 文件
	
		$content = '';
		foreach ($urls as $key => $value) {
			$content .= "$key = $value\n";
		}
		$content .= "\n";
		
		file_put_contents('setup/url.ini', $content);
		$_SESSION['urls'] = $urls;
		exit("0");
	}else{
		exit("error");
	}
?>